package com.liyunc.demo.model.repository;
/**
 * Copyright (c) 2018-2022 ThunderSoft
 * All Rights Reserved by Thunder Software Technology Co., Ltd and its affiliates.
 * You may not use, copy, distribute, modify, transmit in any form this file
 * except in compliance with ThunderSoft in writing by applicable law.
 */

import com.liyunc.demo.model.entity.PermissionInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Set;

/**
 * @author
 * @version 1.0
 * @file
 * @brief
 * @details
 * @date 2022-02-24
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                     NAME               DESCRIPTION
 * 2022-02-24                       Created
 */
public interface PermissionInfoRepository extends JpaRepository<PermissionInfo, Long>,
    JpaSpecificationExecutor<PermissionInfo> {
    @Query(value = "SELECT permissionInfo.*"
        + " FROM user_info userInfo"
        + " LEFT JOIN user_role userRole ON userInfo.id = userRole.user_id"
        + " LEFT JOIN role_info roleInfo ON userInfo.id = roleInfo.id"
        + " LEFT JOIN role_permission rolePermission ON roleInfo.id = rolePermission.role_id"
        + " LEFT JOIN permission_info permissionInfo ON rolePermission.role_id = permissionInfo.id"
        + " WHERE userInfo.id = ?1", nativeQuery = true)
    Set<PermissionInfo> findAllByUser(final Long userId);

}
